﻿@model IEnumerable<Menu>
        @using BBICMS.Infrastructure.UI
@ShowTree(Model)

@helper ShowTree(IEnumerable<Menu> menus)
{
    <ul class="menuTree">
        @foreach (var item in menus)
        {
            <li class="@(item.ChildMenus.Any() ? "hasMenus" : "")">
                <div>
                  @item.Title
                    <a href="@Url.Action("UpDownMove", new { id = item.Id, isUp = true})" class="moveMenu" title="向上" data-id="@item.Id" data-categoryid="@item.CategoryId"><i class="fa fa-chevron-up"></i></a>
                    <a href="@Url.Action("UpDownMove", new { id = item.Id, isUp = false})" class="moveMenu" title="向下" data-id="@item.Id" data-categoryid="@item.CategoryId"><i class="fa fa-chevron-down"></i></a>
                    @*<a href="#" title="新增子菜单" class="menuAdd" data-categoryid="@item.CategoryId" data-parentid="@item.Id" data-toggle="modal" data-target="#ModalMenuForm"><i class="fa fa-plus"></i></a>*@
                   
                    @Ajax.RawActionLink("<i class='fa fa-plus'></i>",
                        "CreateMenu", "Menu",
                        new { categoryId = item.CategoryId, parentId = item.Id },
                        new AjaxOptions { HttpMethod = "Get", UpdateTargetId = "edit-container", OnBegin = "onAjaxBegin", OnComplete = "onAjaxComplete" },
                        new { title = "新增子菜单" })

                    @Ajax.RawActionLink("<i class='fa fa-pencil'></i>",
                        "EditMenu", "Menu",
                        new { id = item.Id },
                        new AjaxOptions { HttpMethod = "Get", UpdateTargetId = "edit-container", OnBegin = "onAjaxBegin", OnComplete = "onAjaxComplete" },
                        new { title = "编辑菜单" })
                    <a href="@Url.Action("Delete", new { id = item.Id})" class="menuRemove" title="移除菜单" data-id="@item.Id" data-categoryid="@item.CategoryId"><i class="fa fa-trash"></i></a>
                   
                </div>
                @if (item.ChildMenus.Any())
                {
                    @ShowTree(item.ChildMenus.OrderByDescending(c=>c.Importance))
                }
            </li>
        }
    </ul>
}